/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mypackage;

import javax.microedition.lcdui.game.GameCanvas;

/**
 *
 * @author zinin
 */
public class MyGameCanvas extends GameCanvas implements Runnable{
    private volatile Thread thread;
    
    public MyGameCanvas(){
        super(false);
    }

    // When the game canvas is hidden, stop the thread.
    protected void hideNotify() {
        thread = null;
        System.out.println("...thread stopped");
    }

    // When the canvas is shown, start a thread to
    // run the game loop.
    protected void showNotify() {
        thread = new Thread(this);
        thread.start();
        System.out.println("thread started...");
    }

    // The game loop.
    public void run() {
        while (thread != null) {
            flushGraphics();
            System.out.println("\t...loop");
            //Thread.currentThread().sleep(10);
        }
    }
    
}
